package com.fhj.bookshop.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fhj.bookshop.annotation.LoginToken;
import com.fhj.bookshop.common.R;
import com.fhj.bookshop.entity.Myorder;
import com.fhj.bookshop.entity.OrderDTO;
import com.fhj.bookshop.service.IMyorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fu
 * @since 2023-12-12
 */
@RestController
public class MyorderController {

    @Autowired
    IMyorderService myorderService;

    @LoginToken
    @RequestMapping(value="/order/{custId}/{proId}/{proNumber}",method = RequestMethod.POST)
    public R Order(@PathVariable Integer custId,@PathVariable Integer proId,@PathVariable Integer proNumber){
        Myorder order=myorderService.createOrder(custId,proId,proNumber);
        return R.ok("订单创建成功").setData(order);
    }
    @LoginToken
    @RequestMapping(value="/order/{orderNumber}",method = RequestMethod.GET)
    public R OrderPage(@PathVariable String orderNumber){
        OrderDTO order=myorderService.findByOrderNumber(orderNumber);
        return R.ok("订单加载成功").setData(order);
    }

    @LoginToken
    @RequestMapping(value="/order/page/{custId}/{pagecode}/{pagesize}",method = RequestMethod.GET)
    public R Page(@PathVariable Integer custId,@PathVariable Integer pagecode,@PathVariable Integer pagesize){
        Page<Myorder> pageInfo=myorderService.orderPageService(pagecode,pagesize,custId);
        return R.ok("订单展示成功").setData(pageInfo);
    }

    @RequestMapping(value = "/adminOrder/{pagecode}/{pagesize}",method = RequestMethod.GET)
    public R AdminPage(@PathVariable Integer pagecode,@PathVariable Integer pagesize){
        Page<Myorder> pageInfo=myorderService.AdminOrderPageService(pagecode,pagesize);
        return R.ok("订单展示成功").setData(pageInfo);
    }
}
